﻿using EYWeb.Core;
using EYWeb.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EYWeb.Frontend.App_Start.Handler
{
    public class CustAuthorizeAttribute: ActionFilterAttribute
    {
        public bool Ignore = true;

        public IRoleAuthorizeService _roleAuthorizeService { get; set; }

        public CustAuthorizeAttribute(bool ignore = true)
        {
            Ignore = ignore;
        }

        
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if(Ignore==false)
            {
                return;
            }
            if(OperatorProvider.Provider.GetCurrent().IsSystem)
            {
                return;
            }
            if(ActionAuthorize(filterContext))
            {

            }


        }

        private bool ActionAuthorize(ActionExecutingContext filterContext)
        {
            /*
             * 1.获取当前用户
             * 2.获取当前模块
             * 3.获取当前Action
             * 4.验证权限
             */
            OperatorModel operatorModel = OperatorProvider.Provider.GetCurrent();
            string role = operatorModel.RoleId;
            string moduleId = WebHelper.GetCookie("CurrentModuleId");
            string action = filterContext.HttpContext.Request.ServerVariables["SCRIPT_NAME"].ToString();


            return true;


        }




    }
}